package beans

import models.RecordM

class Record(
        val id: Int,
        val userId: Int,
        val title: String,
        val desc: String,
        val images: String,
        val price: Double,
        val classes: Int,
        val tags: String,
        val time: Long,
        val longitude: Double,
        val latitude: Double,
        val state: Int
){
    companion object {
        fun from(model: RecordM): Record{
            return Record(
                    id = model[RecordM.ID],
                    userId = model[RecordM.USER_ID],
                    title = model[RecordM.TITLE],
                    desc = model[RecordM.DESC],
                    images = model[RecordM.IMGS],
                    price = model[RecordM.PRICE],
                    time = model.getTimestamp(RecordM.TIME).time,
                    classes = model[RecordM.MAIN_CLASS],
                    tags = model[RecordM.TAGS] ?: "[]",
                    longitude = model[RecordM.LONGITUDE],
                    latitude = model[RecordM.LATITUDE],
                    state = model[RecordM.STATE]
            )
        }
    }
}